#ifndef __Mesh_H__
#define __Mesh_H__

#include "video/SubMesh.h"
#include "video/AxisAlignedBox.h"
#include "video/MeshAnimation.h"
#include <string>
#include "video/RelCounted.h"
#include "video/Material.h"

namespace KEngine
{


class HelperObject
{
public:
	HelperObject();
	virtual ~HelperObject();

public:
	std::string		mName;
	std::string		mParentName;
	std::string		mClassName;
	
	D3DXQUATERNION	mOrientation;
	D3DXVECTOR3		mPosition;
	D3DXVECTOR3		mScale;
	
	D3DXVECTOR3		mBoundingBoxMin;
	D3DXVECTOR3		mBoundingBoxMax;
};
typedef std::vector<HelperObject*> HelperObjectList;
typedef std::vector<HelperObject*>::iterator HelperObjectIterator;
class TextureManager;
class Mesh : public RefCounted
{
public:
	typedef std::map<std::string, MeshAnimation*> AnimationMap;
	typedef AnimationMap::iterator AnimationIterator;
	typedef AnimationMap::const_iterator AnimationConstIterator;
	typedef AnimationMap::value_type AnimationValue;

public:
	Mesh();
	virtual ~Mesh();

	bool		load(const char* filename,TextureManager* textureMgr);

	void		setSubMeshList(SubMeshList& list);
	void		setHelperObjList(HelperObjectList& list);
	
	void		attachSkeleton(Skeleton* skeleton);
	void		dettachSkeleton();

	const char* getName();
	int			getNumSubMeshes();
	SubMesh*	getSubMesh(int idx);
	SubMesh*	getSubMesh(const std::string name);
	int			getNumHelperObjects();
	HelperObject*	getHelperObject(int idx);

	bool		hasMeshAnimation();
	bool		createAnimation(const char* filename, const std::string& name);
	MeshAnimation* getAnimation(const std::string& name);

	bool		hasSkeleton();
	Skeleton*	getSkeleton();

	void		buildBounds();
	const AxisAlignedBox& getBounds() const;

	void	addMtlList(MaterialList& list);
protected:
	std::string			mName;
	SubMeshList			mSubMeshList;
	HelperObjectList	mHelperObjList;
	AnimationMap		mAnimationList;
	Skeleton*			mSkeleton;
	AxisAlignedBox		mAABB;

	MaterialList		mMaterialList;
};

}

#endif //